#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include "Python.h"
#include "pycallbyc.h"
#include <pybind11/embed.h>
#include <pybind11/pybind11.h>


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void log(const QString msg);
    static void log(const std::string msg);
    //void PyLog(const QString msg);
    void PyLogByPath(const char* msg);
    void PyLogByObj(const char* msg);

    int PythonCallAdd();

    void PyCallWriteFile();

    bool PyLogFileLoad();

    bool PyLogFileClose();

private slots:


    void on_pushButton_open_clicked();

    void on_pushButton_send_clicked();

private:
    Ui::MainWindow *ui;
    PyObject* _fileObj = nullptr;
    QString _filePath;
    PyCallByC _pybind;
};

class PyBindC
{
public:
    PyBindC() {
        _gstate = PyGILState_Ensure();  // 仅获取GIL
    }
    ~PyBindC() {
        PyGILState_Release(_gstate);   // 释放GIL
    }
private:
    PyGILState_STATE _gstate;
};


#endif // MAINWINDOW_H
